<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目任务人员管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="项目任务人员管理"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'peopleName',width:120,align:'center'">项目名称</th>
				<th data-options="field:'projectTaskTaskDescription',width:200,align:'center'">任务</th>
				<th data-options="field:'chargePersonSign',width:100,align:'center'">主责任人标识</th>
				<th data-options="field:'duty',width:100,align:'center'">职责</th>
				<th data-options="field:'originalConsumeWorktime',width:100,align:'center'">报填消耗工时</th>
				<th data-options="field:'confirmConsumeWorktime',width:100,align:'center'">确认消耗工时</th>
				<th data-options="field:'id',width:100,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('form', 'addItem')">新增</a>
		</div>
		<div>
			任务:
			<select data-options="editable: false" id = "projectTask" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projectTasks }" >
					<option value = "${item.id }">${item.taskDescription }</option>
				</c:forEach>
			</select>
			人员:
			<select data-options="editable: false" id = "people" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${peoples }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			职责: <input class="easyui-textbox" type="text" id="duty" style="width:240px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="项目任务人员详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:730px; height:240px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
					<tr>
						<td width="120px;" align="right">任务：</td>
						<td>
							<select id="lookProjectTaskId" class="easyui-combobox" data-options="required:true" disabled="disabled">
								<c:forEach var="item" items="${projectTasks }" >
									<option value = "${item.id }">${item.taskDescription }</option>
								</c:forEach>
							</select>
						</td>
						<td width="150px;" align="right">项目任务人员名称：</td>
						<td>
							<select id="lookPeopleId" class="easyui-combobox" data-options="required:true" disabled="disabled">
								<c:forEach var="item" items="${peoples }" >
									<option value = "${item.id }">${item.name }</option>
								</c:forEach>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">主责人标识：</td>
						<td>
							<input class="easyui-textbox" id="lookChargePersonSign" data-options="required:true" readonly="readonly" />
						</td>
						<td align="right">职责：</td>
						<td>
							<input class="easyui-textbox" id="lookDuty" data-options="required:true" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">填报消耗工时：</td>
						<td>
							<input class="easyui-textbox" id="lookOriginalConsumeWorktime" data-options="required:true" readonly="readonly" />
						</td>
						<td align="right">确认消耗工时：</td>
						<td>
							<input class="easyui-textbox" id="lookConfirmConsumeWorktime" data-options="required:true" readonly="readonly" />
						</td>
					</tr>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="addItem" class="easyui-window" title="新增项目任务人员" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:730px; height:240px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editProjetTaskPerson" style = "width:100%; height: 100%">
					<table width="100%" height="100%">
						<tr>
							<td width="120px;" align="right">任务：</td>
							<td>
								<select name = "projectTask.id" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectTasks }" >
										<option value = "${item.id }">${item.taskDescription }</option>
									</c:forEach>
								</select>
							</td>
							<td width="150px;" align="right">项目任务人员名称：</td>
							<td>
								<select name = "people.id" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${peoples }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">主责人标识：</td>
							<td>
								<input class="easyui-textbox" name="chargePersonSign" data-options="required:true" />
							</td>
							<td align="right">职责：</td>
							<td>
								<input class="easyui-textbox" name="duty" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">填报消耗工时：</td>
							<td>
								<input class="easyui-textbox" name="originalConsumeWorktime" data-options="required:true" />
							</td>
							<td align="right">确认消耗工时：</td>
							<td>
								<input class="easyui-textbox" name="confirmConsumeWorktime" data-options="required:true" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="editItem" class="easyui-window" title="编辑项目任务人员" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:730px; height:240px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="editForm" method="post" action="editProjetTaskPerson" style = "width:100%; height: 100%">
					<input type="hidden" id="editId" name = "id">
					<table width="100%" height="100%">
						<tr>
							<td width="120px;" align="right">任务：</td>
							<td>
								<select name = "projectTask.id" id="editProjectTaskId" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${projectTasks }" >
										<option value = "${item.id }">${item.taskDescription }</option>
									</c:forEach>
								</select>
							</td>
							<td width="150px;" align="right">项目任务人员名称：</td>
							<td>
								<select name = "people.id" id="editPeopleId" class="easyui-combobox" data-options="required:true, editable: false">
									<c:forEach var="item" items="${peoples }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right">主责人标识：</td>
							<td>
								<input class="easyui-textbox" name="chargePersonSign" id="editChargePersonSign" data-options="required:true" />
							</td>
							<td align="right">职责：</td>
							<td>
								<input class="easyui-textbox" name="duty" id="editDuty" data-options="required:true" />
							</td>
						</tr>
						<tr>
							<td align="right">填报消耗工时：</td>
							<td>
								<input class="easyui-textbox" name="originalConsumeWorktime" id="editOriginalConsumeWorktime" data-options="required:true" />
							</td>
							<td align="right">确认消耗工时：</td>
							<td>
								<input class="easyui-textbox" name="confirmConsumeWorktime" id="editConfirmConsumeWorktime" data-options="required:true" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + val + ')">查看</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="editItem(' + val + ')">编辑</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="delItem(' + val + ')">删除</a>';
		}
		function search(){
			var dg = $("#dg");
			var projectTask = $("#projectTask").combobox("getValue");
			var people = $("#people").combobox("getValue");
			var duty = $("#duty").textbox("getValue").trim();
			var url = "queryProjetTaskPerson?projectTaskId=" + projectTask + "&peopleId=" + people + "&duty=" + duty;
			dg.datagrid('reload', url);
		}
		function lookDetail(id){
			var params = "id=" + id;
			$.ajax({
			  type: "GET",
			  url: "findProjetTaskPerson",
			  data: params,
			  success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;

						$("#lookProjectTaskId").combobox("setValue", item.projectTaskId);
						$("#lookPeopleId").combobox("setValue", item.peopleId);
						$("#lookChargePersonSign").textbox("setValue", item.chargePersonSign);
						$("#lookDuty").textbox("setValue", item.duty);
						$("#lookOriginalConsumeWorktime").textbox("setValue", item.originalConsumeWorktime);
						$("#lookConfirmConsumeWorktime").textbox("setValue", item.confirmConsumeWorktime);
						
						$('#lookDetail').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function editItem(id){
			data = "id=" + id;
			$.ajax({
			  type: "GET",
			  url: "findProjetTaskPerson",
			  data: data,
			  success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;
						
						$("#editId").val(id);
						$("#editProjectTaskId").combobox("setValue", item.projectTaskId);
						$("#editPeopleId").combobox("setValue", item.peopleId);
						$("#editChargePersonSign").textbox("setValue", item.chargePersonSign);
						$("#editDuty").textbox("setValue", item.duty);
						$("#editOriginalConsumeWorktime").textbox("setValue", item.originalConsumeWorktime);
						$("#editConfirmConsumeWorktime").textbox("setValue", item.confirmConsumeWorktime);
						
						$('#editItem').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的项目任务人员吗？", function(r){
				if(r){
					data = "id=" + id;
					$.ajax({
					  type: "GET",
					  url: "delProjetTaskPerson",
					  data: data,
					  success:function(data){
						  	var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '删除成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  }
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '添加成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '修改成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			//validateMenu
			search();//页面装载完成后加载数据
		});
	</script>
</body>
</html>